package cn.moukou.sbzz.service;

import cn.moukou.sbzz.mapper.OrderFromEnterpriseMapper;
import cn.moukou.sbzz.pojo.OrderFromEnterprise;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderFromEnterpriseService {

    @Autowired
    OrderFromEnterpriseMapper orderFromEnterpriseMapper;

    public int makeOrder(String eid, String bid, String pid, String detail, String productName) {
        OrderFromEnterprise orderFromEnterprise = new OrderFromEnterprise();
        orderFromEnterprise.setEid(eid);
        orderFromEnterprise.setBid(bid);
        orderFromEnterprise.setPid(pid);
        orderFromEnterprise.setDetail(detail);
        orderFromEnterprise.setStatus(0);
        orderFromEnterprise.setProductName(productName);
        return orderFromEnterpriseMapper.insert(orderFromEnterprise);
    }

    public OrderFromEnterprise getOneOrder(String id) {
        return orderFromEnterpriseMapper.selectById(id);
    }

    public int authOrder(String id) {
        OrderFromEnterprise orderFromEnterprise = orderFromEnterpriseMapper.selectById(id);
        orderFromEnterprise.setStatus(1);
        return orderFromEnterpriseMapper.updateById(orderFromEnterprise);
    }

    public List<OrderFromEnterprise> getOrderFromMe(String eid, int status) {
        if(status == 0 || status == 1){
            QueryWrapper<OrderFromEnterprise> wrapper = new QueryWrapper<>();
            wrapper.eq("eid", eid);
            wrapper.eq("status", status);
            return orderFromEnterpriseMapper.selectList(wrapper);
        } else {
            QueryWrapper<OrderFromEnterprise> wrapper = new QueryWrapper<>();
            wrapper.eq("eid", eid);
            return orderFromEnterpriseMapper.selectList(null);
        }
    }

    public List<OrderFromEnterprise> getOrderToMe(String bid, int status) {
        if(status == 0 || status == 1){
            QueryWrapper<OrderFromEnterprise> wrapper = new QueryWrapper<>();
            wrapper.eq("bid", bid);
            wrapper.eq("status", status);
            return orderFromEnterpriseMapper.selectList(wrapper);
        } else {
            QueryWrapper<OrderFromEnterprise> wrapper = new QueryWrapper<>();
            wrapper.eq("bid", bid);
            return orderFromEnterpriseMapper.selectList(null);
        }
    }

}
